package com.jams.goodox.activity.wallet;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.activity.home.HomeActivity;
import com.jams.goodox.activity.serve.meet.MeetRoomListActivity;
import com.jams.goodox.activity.serve.park.ParkingApplyActivity;
import com.jams.goodox.constant.Constants;
import com.jams.goodox.entity.User;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 订单支付成功页面
 * Created by 何二振 on 2016/11/22.
 */
public class PaySuccessActivity extends BaseActivity {

    @Bind(R.id.tv_goto_myorder)
    TextView tvGotoMyorder;
    @Bind(R.id.tv_pay_success_money)
    TextView tvPaySuccessMoney;
    @Bind(R.id.rl_pay_success_money)
    RelativeLayout rlPaySuccessMoney;
    @Bind(R.id.tv_pay_success_tips)
    TextView tvPaySuccessTip;

    private int type;//企业订单支付还是个人支付  1个人订单 2企业订单 3扫码付款
    private double payMoney;//实付金额
    private int paySubCode;//场地预定or停车申请，单独处理支付完成

    @Override
    protected int getLayoutId() {
        return R.layout.pay_sucess_layout;
    }

    @Override
    protected void init() {
        setTitleVisibility(false);
        type = getIntent().getIntExtra("type", -1);
        payMoney = getIntent().getDoubleExtra("payMoney", 0.0);
        paySubCode = getIntent().getIntExtra("paySubCode", 0);
        if (type == 2) {
            tvGotoMyorder.setText("企业服务订单");
        } else if (type == 3) {
            tvGotoMyorder.setText("我的账单");
            tvPaySuccessTip.setText("付款成功");
        }
        tvPaySuccessMoney.setText(User.getPriceStyle(payMoney, ""));
        switch (paySubCode) {
            case Constants.PARKING_CODE:
                tvGotoMyorder.setText("继续申请");
                break;
            case Constants.MEET_CODE:
                tvGotoMyorder.setText("继续申请");
                break;
        }

    }

    @OnClick({R.id.tv_goto_index, R.id.tv_goto_myorder})
    public void onClick(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.tv_goto_index:
                intent.setClass(mContext, HomeActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.putExtra("first", true);
                startActivity(intent);
                this.finish();
                break;
            case R.id.tv_goto_myorder://此处停车申请&场地预定，需要跳转到对应的继续申请界面
                if (paySubCode == Constants.PARKING_CODE) {
                    intent.setClass(mContext, ParkingApplyActivity.class);
                    intent.putExtra("paySuccess", true);
                    startActivity(intent);
                    finish();
                    return;
                }
                if (paySubCode == Constants.MEET_CODE) {
                    intent.setClass(mContext, MeetRoomListActivity.class);
                    intent.putExtra("paySuccess", true);
                    startActivity(intent);
                    finish();
                    return;
                }
                // 间接跳转到 MyOrderActivity
                if (type == 2) {//企业订单
                    intent.setClass(mContext, HomeActivity.class);
                    intent.putExtra(HomeActivity.MODE, 30);
                    startActivity(intent);
                } else if (type == 3) {//账单详情页
                    intent.setClass(mContext, HomeActivity.class);
                    intent.putExtra(HomeActivity.MODE, 29);
                    startActivity(intent);
                } else {
                    intent.setClass(mContext, HomeActivity.class);
                    intent.putExtra(HomeActivity.MODE, 27);
                    startActivity(intent);
                }
                this.finish();
                break;
        }
    }

    @Override
    public void onBackPressed() {
        return;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
